package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Room;
import cn.wolfcode.trip.base.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rooms")
public class RoomController {
    //根据酒店房间id查询房间信息和酒店信息
    @Autowired
    private IRoomService service;

    @RequestMapping("{rid}")
    public Room queryRoomById(@PathVariable Long rid){
        Room room=service.queryRoomById(rid);
        return room;
    }

    //房间被预定后根据房间id减少房间数量
    @GetMapping
    public Room changeSum(Long id){
        //减少房间数量
        service.changeSumById(id);
        //查询最新房间数量渲染到网页
        Room room=service.queryCurrentSum(id);

        return room;
    }




}
